package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	PhoneNum      string `gorm:"type:char(11);not ull;comment:'手机号'"`
	Pwd           string `gorm:"type:varchar(32);not ull;comment:'密码'"`
	NickName      string `gorm:"type:varchar(300);not ull;comment:'昵称'"`
	AvatarLink    string `gorm:"type:varchar(300);comment:'头像'"`
	RegisterTime  string `gorm:"type:varchar(50);not ull;comment:'注册时间'"`
	AccountStatus string `gorm:"type:enum('1','0');default:'0';comment:'账号状态'"`
	FollowNum     int64  `gorm:"type:int(11);default:0;comment:'关注数'"`
	FansNum       int64  `gorm:"type:int(11);default:0;comment:'粉丝数'"`
	UserLevel     int64  `gorm:"type:int(11);default:0;comment:'用户等级'"`
}

func (u *User) FindUserByPhoneNum(db *gorm.DB, num string) error {
	return db.Debug().Where("phone_num=?", num).First(u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) UserUpdate(db *gorm.DB, num string) error {
	return db.Debug().Where("phone_num=?", num).Updates(u).Error
}
